# -*- coding:utf-8 -*-
from tornado import gen

from common import utiltool
from appcommon.framework import BaseHandler


class DemoHandler(BaseHandler):
    """
    样例接口
    """
    # @decorator.check_params(['product_type', 'class_id', 'site_id'])
    # @decorator.verify_params
    @gen.coroutine
    def get(self):
        utiltool.response_write(self, "this is MTD_Manage")


from common import timetool
class LamianHandler(BaseHandler):
    """
    周五拉面
    """
    # @decorator.check_params(['product_type', 'class_id', 'site_id'])
    # @decorator.verify_params
    @gen.coroutine
    def get(self):
        day = timetool.get_current_date()
        f = open('lamian', 'r')
        data = f.read().decode('utf-8')
        f.close()

        if data:
            day_o = data.split()[0]
            phone = data.split()[1]
            drivers = data.split()[2]

            if day == day_o:
                res = u"今日订餐人员:{}\n今日司机：{}".format(phone, drivers)
            else:
                f1 = open('lamian', 'w')
                import random

                phone_list = [u"帅琼", u"猥琐袁", u"彬哥", u"宗大", u"老于", u"学帅"]
                car_list = [u"帅琼", u"猥琐袁", u"彬哥", u"宗大", u"学帅"]

                phone_index = random.randint(0, 99) % 6
                car_index1 = random.randint(0, 99) % 5
                car_index2 = random.randint(0, 99) % 5

                while car_index1 == car_index2:
                    car_index2 = random.randint(0, 99) % 5

                phone = phone_list[phone_index]
                drivers = car_list[car_index1] + ',' + car_list[car_index2]
                res = u"今日订餐人员:{}\n今日司机：{}".format(phone, drivers)
                wdata = day + u' ' + phone + u' ' + drivers
                f1.write(wdata.encode('utf-8'))
                f1.close()
        else:
            f1 = open('lamian', 'w')
            import random

            phone_list = [u"帅琼", u"猥琐袁", u"彬哥", u"宗大", u"老于", u"学帅"]
            car_list = [u"帅琼", u"猥琐袁", u"彬哥", u"宗大", u"学帅"]

            phone_index = random.randint(0, 99) % 6
            car_index1 = random.randint(0, 99) % 5
            car_index2 = random.randint(0, 99) % 5

            while car_index1 == car_index2:
                car_index2 = random.randint(0, 99) % 5

            phone = phone_list[phone_index]
            drivers = car_list[car_index1] + ',' + car_list[car_index2]
            res = u"今日订餐人员:{}\n今日司机：{}".format(phone, drivers)
            wdata = day +u' '+phone+u' '+drivers
            f1.write(wdata.encode('utf-8'))
            f1.close()
        utiltool.response_write(self, res)